#ifndef POSITIONCALCULATOR_H
#define POSITIONCALCULATOR_H

#include <QObject>
#include <QRubberBand>
#include <QMouseEvent>
#include <QDebug>

class QPositionCalculator : public QObject
{
    Q_OBJECT
public:
    explicit QPositionCalculator(QObject *parent = NULL);
    ~QPositionCalculator();

    void Reset();
    void Calculate(const QPoint &globalMousePosition, const QRect &frameRect);

    // 设置窗体移动
    void SetFormMovable(bool movable);
    // 设置窗体缩放
    void SetFormResizable(bool resizable);
    // 设置橡皮筋移动
    void SetFormRubberBandOnMove(bool movable);
    // 设置橡皮筋缩放
    void SetFormRubberBandOnResize(bool resizable);
    // 设置边框的宽度
    void SetFormBorderWidth(uint width);
    // 设置标题栏高度
    void SetFormTitleBarHeight(uint height);

    bool IsFormResizable();
    bool ISFormMovable();
    bool IsFormRubberBandOnMove();
    bool IsFormRubberBandOnResisze();

    unsigned long GetFormBorderWidth();
    unsigned long GetFormTitleBarHeight();

    void UpdateCursorShape(const QPoint &globalMousePosition);
    void ResizeForm(const QPoint &globalMousePosition);
    // 更新橡皮筋状态
    void UpdateRubberBandStatus();

signals:

public slots:
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseReleaseEvent(QMouseEvent *event);

protected:
    bool OnEdges              : true;
    /** 四条边 */
    bool OnLeftEdge           : true;
    bool OnRightEdge          : true;
    bool OnTopEdge            : true;
    bool OnBottomEdge         : true;
    /** 四个角 */
    bool OnTopLeftEdge        : true;
    bool OnBottomLeftEdge     : true;
    bool OnTopRightEdge       : true;
    bool OnBottomRightEdge    : true;

    bool FormIsMovable        : true;
    bool FormIsResizable      : true;
    bool FormRubberBandIsOnResize : true;
    bool FormRubberBandIsOnMove   : true;
    bool CursorShapeIsChanged : true;

    QWidget* ParentForm;
    QRubberBand* FormRubberBand;
    Qt::WindowFlags FormFlags;
    QPoint GlobalMousePostion;

    static int FormBorderWidth;
    static int FormTitleBarHeight;
};

#endif // POSITIONCALCULATOR_H
